package com.stylefeng.guns.modular.hhtb.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.hhtb.model.UsersBankcards;
import com.stylefeng.guns.modular.hhtb.model.UsersBankcardsDto;
import com.stylefeng.guns.modular.hhtb.service.IUsersBankcardsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 银行卡表控制器
 *
 * @author fengshuonan
 * @Date 2018-09-12 09:39:15
 */
@Controller
@RequestMapping("/usersBankcards")
public class UsersBankcardsController extends BaseController {

    private String PREFIX = "/hhtb/usersBankcards/";

    @Autowired
    private IUsersBankcardsService usersBankcardsService;

    /**
     * 跳转到银行卡表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "usersBankcards.html";
    }

    /**
     * 跳转到添加银行卡表
     */
    @RequestMapping("/usersBankcards_add")
    public String usersBankcardsAdd() {
        return PREFIX + "usersBankcards_add.html";
    }

    /**
     * 跳转到修改银行卡表
     */
    @RequestMapping("/usersBankcards_update/{usersBankcardsId}")
    public String usersBankcardsUpdate(@PathVariable Integer usersBankcardsId, Model model) {
        UsersBankcards usersBankcards = usersBankcardsService.selectById(usersBankcardsId);
        model.addAttribute("item",usersBankcards);
        LogObjectHolder.me().set(usersBankcards);
        return PREFIX + "usersBankcards_edit.html";
    }
    /**
     * 跳转到修改银行卡表
     */
    @RequestMapping("/usersBankcards_info/{usersBankcardsId}")
    public String usersBankcardsInfo(@PathVariable Integer usersBankcardsId, Model model) {
        UsersBankcardsDto usersBankcards = usersBankcardsService.selectByBankId(usersBankcardsId);
        model.addAttribute("item",usersBankcards);
        LogObjectHolder.me().set(usersBankcards);
        return PREFIX + "usersBankcards_info.html";
    }

    /**
     * 获取银行卡表列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(UsersBankcardsDto usersBankcardsDto) {
        Page<UsersBankcardsDto> page = new PageFactory<UsersBankcardsDto>().defaultPage();
        List<UsersBankcardsDto> list = usersBankcardsService.selectAll(page,usersBankcardsDto);
        return list;
    }

    /**
     * 新增银行卡表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(UsersBankcards usersBankcards) {
        usersBankcardsService.insert(usersBankcards);
        return SUCCESS_TIP;
    }

    /**
     * 删除银行卡表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer usersBankcardsId) {
        usersBankcardsService.deleteById(usersBankcardsId);
        return SUCCESS_TIP;
    }

    /**
     * 修改银行卡表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(UsersBankcards usersBankcards) {
        usersBankcardsService.updateById(usersBankcards);
        return SUCCESS_TIP;
    }

    /**
     * 银行卡表详情
     */
    @RequestMapping(value = "/detail/{usersBankcardsId}")
    @ResponseBody
    public Object detail(@PathVariable("usersBankcardsId") Integer usersBankcardsId) {
        return usersBankcardsService.selectById(usersBankcardsId);
    }
}
